<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="UTF-8"
	src="../js/prefixfree.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/base.css"
	media="all" />
<link rel="stylesheet" type="text/css" href="../css/self.css"
	media="all" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="../viewport" content="width=device-width, initial-scale=1">
<link href="../css/bootstrap.css" rel="stylesheet">
<link href="../css/alert.css" rel="stylesheet">
<script src="../js/jquery-1.12.4.min.js"></script>
<script src="../js/bootstrap.js"></script>
</head>
<body>
	<table class="table table-striped">
		<tr>
			<td class="active">ID</td>
			<td class="active">姓名</td>
			<td class="active">电话</td>
			<td class="active">管理员权限</td>
			<td class="active">操作</td>
		</tr>
		<c:forEach var="user" items="${users }" varStatus="status">
			<tr>
				<td>${user.uid }</td>
				<td>${user.uname }</td>
				<td>${user.tel }</td>
				<td>${user.isadmin }</td>
				<td class="modify"><button id="del" onclick="del('${user.uid}','${user.isadmin }')"
						class="btn btn-default" type="button">删除</button>
					<button id="" onclick="modify('${user.uid }','${user.uname}','${user.tel}','${user.isadmin }')"
						class="btn btn-default" type="button">修改</button></td>
			</tr>
		</c:forEach>
	</table>
	<ul class="statusbar">
		<nav aria-label="...">
			<ul class="pager">
				<li><a href="javascript:void(0)" onclick="user_page(-1)">上一页</a></li>&nbsp;&nbsp;
				<li><a href="javascript:void(0)" onclick="user_page(1)">下一页</a></li>
			</ul>
		</nav>
	</ul>
	
	
<!-- 弹框部分代码 -->
<div class="popOutBg"></div>
<div class="popOut">
	<span title="关闭"> x </span>
	<table>
		<caption>请输入需要修改的内容</caption>
		<input id="modify_uid" type="hidden" value="">
		<tr>
			<td width="120">姓名：</td>
			<td><input id="modify_name" type="text" class="inp" value="" /></td>
		</tr>
		<tr>
			<td>电话：</td>
			<td><input id="modify_tel" type="text" class="inp" value="" /></td>
		</tr>
		<tr>
			<td>管理员权限：</td>
			<td><input id="modify_isadmin" type="text" class="inp" placeholder="请输入 '是' 或 '否' " /></td>
		</tr>
		<tr>
			<td colspan="2"><input type="button" id="modify_sub" class="change_submit" value="提 交" /></td>
		</tr>
	</table>
</div>
	<script>
		function user_page(p){
			top.console.info(666);
			console.log(p);
			var href = location.href;
			var hash = location.hash;
			var page = hash.split("=")[1];
			var newPage = parseInt(page) + parseInt(p);
			if(newPage<=0){
				newPage=1;
			}
			console.log(page);
			console.log(href);
			console.log(newPage);
			$.post("../../admin_user",{
				op:'getUserByPage',
				page:newPage
			},function(data){
				console.log(data);
				if(data>0){
					location.href="http://localhost:8080/Xiaomi/admin/back/users.jsp#page="+data;
					location.reload();
				}
			});
		}
		function show(param){
			if(arguments[1] == true){
				return document.querySelectorAll(param);
			}else{
				return document.querySelector(param);
			}
		}
		function modify(uid,uname,tel,isadmin){
			$("#modify_uid").val(uid);
			document.getElementById('modify_name').value=uname;
			//console.log(  $("#modify_name").attr("class","xxx") );
			document.getElementById('modify_tel').value=tel;
			if(isadmin==0){
				document.getElementById('modify_isadmin').value='普通用户';
			}
			if(isadmin==1){
				document.getElementById('modify_isadmin').value='管理员';
			}
			show(".popOut").style.display = "block";
			ani();
			show(".popOutBg").style.display = "block";
			function ani(){
				show(".popOut").className = "popOut ani";
			}
			$(".popOut > span").click(function(){
				show(".popOut").style.display = "none";
				show(".popOutBg").style.display = "none";
			});
		}
		$("#modify_sub").click(function(){
			var uid = $("#modify_uid").val();
			var uname = $("#modify_name").val();
			var tel = $("#modify_tel").val();
			if( uname==null || uname=="" || tel == "" || tel==null ){
				alert("信息不可为空");
				return;
			}
			$.post("../../admin_user",{
				op:'user_modify',
				uid:uid,
				uname:uname,
				tel:tel
			},function(data){
				if(data>0){
					var hash = location.hash;
					var page = hash.split("page=")[1];
					$.post("../../admin_user",{
						op:'getUserByPage',
						page:page
					},function(data){
						console.log(data);
						if(data>0){
							$("#frame").attr("src", "users.jsp#page=1");
						}else{
							alert("暂无数据");
						}
					},"json");
					alert("修改成功!");
					location.reload();
				}else{
					alert("修改失败!");
				}
			});
		});
		function del(uid,isadmin){
			if(uid==${admin.uid}){
				var r = confirm("删除自己您可能无法登录！是否继续？");
				if (r == false) {
					return;
				}else{
					top.location.href="../index.html";
				}
			}
			$.post("../../admin_user",{
				op:'user_del',
				uid:uid
			},function(data){
				if(data>0){
					var hash = location.hash;
					var page = hash.split("page=")[1];
					$.post("../../admin_user",{
						op:'getUserByPage',
						page:page
					},function(data){
						if(data>0){
							location.reload();
						}else{
							alert("暂无数据");
						}
					},"json");
					alert("删除成功!");
					location.reload();
				}else{
					alert("删除失败!");
				}
			});
		}
	</script>
</body>